home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / amc / amc_install.exe / {app} / Scripts / MovieMeter (NL).ifs < prev    next >
Encoding:
Text File  |  2005-03-13  |  7.7 KB  |  258 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=JanC (<link>amc-script@janc.cjb.net</link>)
  8. Title=MovieMeter.nl
  9. Description=MovieMeter.nl import script
  10. Site=www.moviemeter.nl
  11. Language=NL
  12. Version=
  13. Requires=3.5.0
  14. Comments= Now works with the new site !!| partially based on other import scripts| corrections by <link>rolandb5@hotmail.com</link>|
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program MovieMeter;
  23.  
  24. var
  25.   MovieName: string;
  26.  
  27.  
  28. procedure AnalyzeMoviePage(Address: string);
  29. var
  30.   Page: TStringList;
  31.   Line, Value: string;
  32.   LineNr: Integer;
  33.   I: Integer;
  34.   BeginPos, EndPos: Integer;
  35. begin
  36.   // get movie page
  37.   Page := TStringList.Create;
  38.   Page.Text := GetPage(Address);
  39.  
  40.   // get URL
  41.   SetField(fieldURL, Address);
  42.  
  43.   // find line with titles & year
  44.   LineNr := 0;
  45.   repeat
  46.     LineNr := LineNr + 1;
  47.     Line := Page.GetString(LineNr);
  48.   until Pos('<p class="kop">', Line) > 0;
  49.   // get original(?) title
  50.   BeginPos := Pos('<p class="kop">', Line);
  51.   Delete(Line, 1, BeginPos-1);
  52.   BeginPos := Pos('<p class="kop">', Line) + Length('<p class="kop">');
  53.    EndPos := Pos('(', Line) - Length(' ');
  54.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  55.   HTMLDecode(Value);
  56.   SetField(fieldOriginalTitle, Value);
  57.   Delete(Line, 1, EndPos);
  58.  
  59.   // get year
  60.   BeginPos := Pos('(', Line) + Length('(');
  61.   EndPos := pos(')', Line);
  62.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  63.   HTMLDecode(Value);
  64.   SetField(fieldYear, Value);
  65.  
  66.   // get first alternative title???
  67.   LineNr := LineNr + 1;
  68.   Line := Page.GetString(LineNr);
  69.   BeginPos := Pos('Alternatieve titel:', Line) + Length('    Alternatieve titel:');
  70.     if BeginPos > 0 then begin
  71.     EndPos := pos('</b>', Line);
  72.     Value := Copy(Line, BeginPos, EndPos - BeginPos);
  73.     HTMLDecode(Value);
  74.     SetField(fieldTranslatedTitle, Value);
  75.   end;
  76.  
  77.   // find line with country, cat & length
  78.   repeat
  79.     LineNr := LineNr + 1;
  80.     Line := Page.GetString(LineNr);
  81.   until Pos('geregisseerd door', Line) > 0;
  82.   // get country
  83.   BeginPos := 1;
  84.   EndPos := Pos('<br>', Line);
  85.   Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  86.   HTMLDecode(Value);
  87.   SetField(fieldCountry, Value);
  88.   Delete(Line, 1, EndPos + Length('<br>') - 1);
  89.   // get category
  90.   BeginPos := 1;
  91.   EndPos := Pos('<br>', Line);
  92.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  93.   HTMLDecode(Value);
  94.   SetField(fieldCategory, Value);
  95.   Delete(Line, 1, EndPos + Length('<br>') - 1);
  96.   // get length
  97.   BeginPos := 1;
  98.   EndPos := Pos(' minuten <br>', Line);
  99.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  100.   HTMLDecode(Value);
  101.   SetField(fieldLength, Value);
  102.  
  103.   // find line with director & actors
  104.   repeat
  105.     LineNr := LineNr + 1;
  106.     Line := Page.GetString(LineNr);
  107.   until Pos('<a href="?regisseur=', Line) > 0;
  108.   // get director
  109.   BeginPos := Pos('">', Line) + Length('">');
  110.   EndPos := Pos('</a>', Line);
  111.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  112.   HTMLDecode(Value);
  113.   SetField(fieldDirector, Value);
  114.   Delete(Line, 1, EndPos-1);
  115.   // get actors
  116.   BeginPos := Pos('<br>met ', Line) + Length('<br>met ');
  117.   EndPos := Pos('</p><p>', Line);
  118.   Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  119.   HTMLDecode(Value);
  120.   SetField(fieldActors, Trim(Value));
  121.  
  122.   Value := '';
  123.   repeat
  124.     // get line with description
  125.  
  126.     LineNr := LineNr + 1;
  127.     Line := Page.GetString(LineNr);
  128.     if Pos('</p>', Line) = 0 then begin
  129.     Value := Value + Line;
  130.     end;
  131.     // get description
  132.  
  133.     if Pos('</p>', Line) > 0 then begin
  134.       BeginPos := 1;
  135.       EndPos := Pos('</p>', Line);
  136.       Value := Value + Copy(Line, BeginPos, EndPos - BeginPos);
  137.  
  138.     end;
  139.     HTMLDecode(Value);
  140.  
  141.   until Pos('</p>', Line) > 0;
  142.   Value := StringReplace(Value, #9, '');
  143.   SetField(fieldDescription, Value);
  144.   // find line with cover picture
  145.   repeat
  146.     LineNr := LineNr + 1;
  147.     Line := Page.GetString(LineNr);
  148.   until Pos('<img src="images/covers/', Line) > 0;
  149.   // get cover picture
  150.   BeginPos := Pos('<img src="', Line) + Length('<img src="');
  151.   EndPos := Pos('" ', Line);
  152.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  153.   GetPicture('http://www.moviemeter.nl/' + Value);
  154.  
  155.   // find line with rating
  156.   repeat
  157.     LineNr := LineNr + 1;
  158.     Line := Page.GetString(LineNr);
  159.   until Pos('<td class="stembody">', Line) > 0;
  160.   LineNr := LineNr + 1;
  161.   Line := Page.GetString(LineNr);
  162.   // get average rating (range 0.00-5.00 on the site, range 0-10 in AMC)
  163.   BeginPos := Pos('<br>', Line) + Length('<br>');
  164.   EndPos := Pos(' gemiddeld', Line);
  165.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  166.   I := StrToInt(Copy(Value, 1, 1), 0) * 100 + StrToInt(Copy(Value, 3, 2), 0);
  167.   Value := IntToStr(Round(I/50));
  168.   SetField(fieldRating, Value);
  169.  
  170.   //DisplayResults;
  171.   Page.Free;
  172. end;
  173.  
  174.  
  175. procedure AnalyzeResultsPage(Address: string);
  176. var
  177.   Page: TStringList;
  178.   Line: string;
  179.   MovieAddress: string;
  180.   LineNr: Integer;
  181.   MovieTitle: string;
  182.   StartPos, EndPos: Integer;
  183. begin
  184.   // get results page
  185.   Page := TStringList.Create;
  186.   Page.Text := GetPage(Address);
  187.  
  188.   // get redirect javascript
  189.   Line := Page.GetString(Page.Count-1);
  190.  
  191.   // if only 1 movie found --> redirect to movie page
  192.   if Pos('location.replace("?film=', Line) <> 0 then begin
  193.     StartPos := Pos('?film=', Line);
  194.     EndPos := Pos('");</script>', Line);
  195.     MovieAddress := 'http://moviemeter.nl/' + Copy(Line, StartPos, EndPos - StartPos);
  196.     AnalyzeMoviePage(MovieAddress);
  197.   end
  198.   // more than 1 movie found
  199.   else if Pos('location.href = "?searchresults"', Line) <> 0 then begin
  200.     PickTreeClear;
  201.  
  202.     // get results page
  203.     Page.Text := GetPage('?searchresults');
  204.  
  205.     // find line with results
  206.     LineNr := 0;
  207.     repeat
  208.       LineNr := LineNr + 1;
  209.       Line := Page.GetString(LineNr);
  210.     until Pos('<!--m-->', Line) > 0;
  211.  
  212.     // find individual results delimited by <!--m--> & <!--n-->'
  213.     StartPos := Pos('<!--m-->', Line);
  214.     while StartPos > 0 do begin
  215.       Delete(Line, 1, StartPos-1);
  216.       StartPos := Pos('<!--m-->', Line) + Length('<!--m--><a href="');
  217.       EndPos := Pos('">', Line);
  218.       MovieAddress := Copy(Line, StartPos, EndPos - StartPos);
  219.      
  220.       StartPos := Pos('">', Line) + Length('"><b>');
  221.       EndPos := Pos('<br>', Line);
  222.       MovieTitle := Copy(Line, StartPos, EndPos - StartPos);
  223.       HTMLRemoveTags(MovieTitle);
  224.       HTMLDecode(Movietitle);
  225.      
  226.       PickTreeAdd(MovieTitle, 'http://www.moviemeter.nl/' + MovieAddress);
  227.      
  228.       Delete(Line, 1, EndPos-1);
  229.       StartPos := Pos('<!--m-->', Line);
  230.     end;
  231.  
  232.     // if user picks a movie from the results list, import movie details
  233.     if PickTreeExec(Address) then
  234.       AnalyzeMoviePage(Address);
  235.   end
  236.   // no movies found
  237.   else begin
  238.     ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  239.   end;
  240.  
  241.   Page.Free;
  242. end;
  243.  
  244.  
  245. begin
  246.   if CheckVersion(3,5,0) then     // is this really the minimum version?
  247.   begin
  248.     MovieName := GetField(fieldOriginalTitle);
  249.     if MovieName = '' then
  250.       MovieName := GetField(fieldTranslatedTitle);
  251.     if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then
  252.     begin
  253.       AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName));
  254.     end;
  255.   end else
  256.     ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)');
  257. end.
  258.